﻿<########################################################################################################
	
	.AUTHOR
		Rahul G. Babar																		 
	
	.SYNOPSYS
		Test if emails are working on SharePoint Server.
	
	.DESCRIPTION
	    Test if emails are working on SharePoint Server.
	
	.PARAMETER Web
		Website url on which you want to test whether or not emails are working.
		
	.PARAMETER To
		The test email address to which you want to send email from SharePoint.
	
	.EXAMPLE
		.\TestSharePointEmailWorking.ps1 -Web http://SP2010Server/Training -To test@test.com		 
    
########################################################################################################>

[CmdletBinding()]
Param(
   [Parameter(Mandatory=$true,Position=1)]
   [string]$Weburl,
   [Parameter(Mandatory=$true,Position=2)]
   [string]$To
) 

function LoadSharePointPowerShellEnvironment
{	
	write-host "Setting up PowerShell environment for SharePoint" -foregroundcolor Yellow
	write-host 
	Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
	write-host "SharePoint PowerShell Snapin loaded." -foregroundcolor Green
	write-host 
}

LoadSharePointPowerShellEnvironment
$Web = Get-SPWeb $Weburl
Write-Host "Checking if emails are working on site $($Web.Title)..." -ForegroundColor Yellow
Write-Host
$Sent = [Microsoft.Sharepoint.Utilities.SpUtility]::SendEmail($Web, 0, 0, $To, "Test mail subject", "Thhis is a test mail")

if($Sent)
{
	Write-Host "Emails are working on site $($Web.Title)." -ForegroundColor Green
	Write-Host
}
else
{
	Write-Host "Emails are not working on site $($Web.Title)." -ForegroundColor Red
	Write-Host
}
